package com.ssy.lingxi.message.repository;


import com.ssy.lingxi.message.entity.ImChatRecordDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * IM聊天记录 - 实体仓库
 * @author fhj
 * @version 2.0.0
 * @date 2021/03/29
 */
@Repository
public interface ImChatRecordRepository extends JpaRepository<ImChatRecordDO, Long>, JpaSpecificationExecutor<ImChatRecordDO> {


    @Query(value = "SELECT count(*) FROM msg_im_chat_record WHERE (from_member_id = :fromMemberId AND to_member_id = :toMemberId) OR (from_member_id = :toMemberId AND to_member_id = :fromMemberId) LIMIT 1", nativeQuery = true)
    Integer existsByFromAndToOrToAndFrom(@Param("fromMemberId")String fromMemberId, @Param("toMemberId")String toMemberId);


}
